package org.example.mybootproject;


import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;

@RestController
public class PersonController {
    //告诉springboot， 我这里需要一个PersonMapper对象

    @Resource
    private PersonMapper personMapper;
    @RequestMapping("insert")
    public String insert(PersonBean personBean) throws ClassNotFoundException, SQLException {

        if (personBean.getName()==null){
            return "名字不能为空";
        }
        if (personBean.getAge()<1){
            return "年龄必须大于等于1";
        }
        if (personBean.getSex()==null){
            return "性别不能为空";
        }
        if (personBean.getAddress()==null){
            return "地址不能为空";
        }
        int i = personMapper.save(personBean);
        if (i>0){
            return "插入成功";
        }else{
            return "插入失败";
        }
    }

    @RequestMapping("list")
    public List<PersonBean> list(){
        return personMapper.list();
    }
}
